<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%
    request.setAttribute("basePath", request.getContextPath());
%>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <script type="text/javascript" src="${basePath}/resources/jquery/jquery-1.6.4.min.js"></script>
    <script type="text/javascript" src="${basePath}/resources/js/common/json2.js"></script>
    <link rel="stylesheet" href="${basePath}/component/JQueryzTreev3.5.14/css/zTreeStyle/zTreeStyle.css"
          type="text/css">
    <script type="text/javascript" src="${basePath}/component/JQueryzTreev3.5.14/js/jquery.ztree.core-3.5.js"></script>
    <script type="text/javascript"
            src="${basePath}/component/JQueryzTreev3.5.14/js/jquery.ztree.excheck-3.5.min.js"></script>
    <script type="text/javascript"
            src="${basePath}/component/JQueryzTreev3.5.14/js/jquery.ztree.exhide-3.5.min.js"></script>

    <script>
        $(function () {
            $.get('${basePath}/s/uc/lb/l', function (data) {
                var zNodes = new Array();

                //是否流程待办组件,流程待办组件只显示待办
                var workflow = '${workflow}';
                var isWorkflow = (workflow != null && workflow != '');

                var chkStyle = '${chkStyle}';
                var enable = (chkStyle != null && chkStyle != '');
                var isSearch = '${isSearch}';
                $.each($.parseJSON(data), function (i, item) {
                    var obj = new Object();
                    obj.id = item.wid;
                    obj.pId = item.upid;
                    obj.name = item.name;
                    if (item.wid.length == 1) {
                        obj.open = true;
                    }
                    if (item.wid == '0') {
                        obj.nocheck = true;
                    }
                    if(isWorkflow){
                        if(item.lx!='1' || item.wid.length == 1){
                            return;
                        }
                        if(item.upid.length == 1 || item.wid.length == 1){
                            obj.nocheck = true;
                        }
                    }
                    if (enable && item.state == '0') {
                        obj.isHidden = true;
                    }
                    if (item.sfxz == '1') {
                        obj.checked = true;
                    }
                    zNodes.push(obj);
                });


                var setting = {
                    data: {
                        simpleData: {
                            enable: true
                        }
                    },
                    check: {
                        enable: enable,
                        chkStyle: chkStyle,
                        radioType: "level",
                        chkDisabledInherit: true,
                        chkboxType: {"Y": "", "N": ""}
                    },
                    callback: {
                        onClick: doClickTreeNode,
                        onCheck: onCheckTreeNode
                    }
                };
                $.fn.zTree.init($("#tree"), setting, zNodes);
            });
        });

        /**
         * 树结构点击事件
         */
        function doClickTreeNode(event, treeId, treeNode) {
            $("#menuContentFrame", parent.document).attr("src", "${basePath}/s/uc/lb/e?wid=" + treeNode.id);
        }

        /**
         * 用于门户界面打开树时初始化勾选的
         */
        function init(){
            var treeObj = $.fn.zTree.getZTreeObj("tree");
            if($(".mxtable",parent.document)[0]){
                $(".mxtable tr[lbxxid]",parent.document).each(function(){
                    var item = treeObj.getNodesByParam("id", $(this).attr("lbxxid"),null)[0];
                    treeObj.checkNode(item, true, false);
                    if(parent.lbxxEdit) {
                        parent.lbxxEdit.lbxxList.push(item);
                    }else if(parent.workflowEdit){
                        parent.workflowEdit.lbxxList.push(item);
                    }
                });
            }
        }

        /**
         * 树结构checkbox、radio点击事件
         */
        function onCheckTreeNode(event, treeId, treeNode) {
            var treeObj = $.fn.zTree.getZTreeObj("tree");
            var checks = "";
            treeObj.checkNode(treeNode.getParentNode(), false, false);
            if (treeNode.children != null) {
                $.each(treeNode.children, function (i, item) {
                    treeObj.checkNode(item, false, false);
                    if (item.isParent) {
                        $.each(item.children, function (j, jitem) {
                            treeObj.checkNode(jitem, false, false);
                        })
                    }
                })
            }

            if(parent.lbxxEdit){
                parent.lbxxEdit.lbxxList = new Array();
                $.each(treeObj.getCheckedNodes(true), function (i, item) {
                    parent.lbxxEdit.lbxxList.push(item);
                });
            } else if(parent.workflowEdit){
                parent.workflowEdit.lbxxList = new Array();
                $.each(treeObj.getCheckedNodes(true), function (i, item) {
                    parent.workflowEdit.lbxxList.push(item);
                });
            }
        }
    </script>
</head>
<body <c:if test="${chkStyle ==null || chkStyle == ''}">  </c:if>>
<input type="hidden" id="chooseNode"/>
<input type="hidden" id="tmid" value="${tmid}"/>

<div class="treeDiv">
    <ul id="tree" class="ztree"></ul>
</div>
</body>
</html>
